package com.lf.web.controller;

import com.lf.web.entity.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import java.util.Date;

/**
 * Created by LF on 2017/5/4.
 */
@Controller
public class UserController {


    @RequestMapping(value = "/user", method = RequestMethod.POST)
    public void addUser(@RequestBody User user) {
        System.out.println("add user");
    }

    @RequestMapping(value = "/user/{id}", method = RequestMethod.GET)
    @ResponseBody
    public User getUser(@PathVariable String id) {
        User user = new User();
        user.setAge(10);
        user.setName("张三");
        user.setDate(new Date());
        return user;

    }

    @RequestMapping(value = "/user/2", method = RequestMethod.GET)
    public ModelAndView getUser2() {
        ModelAndView modelAndView = new ModelAndView();
        User user = new User();
        user.setDate(new Date());
        user.setAge(10);
        user.setName("张三");
        modelAndView.setViewName("index");
        modelAndView.addObject("user",user);
        return modelAndView;

    }
}
